<?php
namespace App\Admin\Controllers\Operation;

use App\Models\Basics\AmazonCountry;;
use App\Models\Operation\Business;
use App\Models\Product\ProductClassify;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
class BusinessController extends AdminController{

    protected $title = 'BUSINESS数据';

    protected function grid()
    {
        $grid = new Grid(new Business());
        $grid->model()->orderBy('id', 'DESC')->paginate(20);
        $grid->column('id','ID')->totalRow('ALL');
        $grid->column('report_date','报表日期');
        $grid->column('country.country','国家');
        $grid->column('parent_asin','(Parent) ASIN');
        $grid->column('child_asin','(Child) ASIN');
        $grid->column('sku.psku_code','SKU');
        $grid->column('classify.title','品类');
        $grid->column('sessions_app','SessionsApp')->totalRow();
        $grid->column('sessions_browser','SessionsBrowser')->totalRow();
        $grid->column('sessions_total','SessionsTotal')->totalRow();
        $grid->column('page_views_app','PageViewsApp')->totalRow();
        $grid->column('page_views_browser','PageViewsBrowser')->totalRow();
        $grid->column('page_views_total','PageViewsTotal')->totalRow();
        $grid->column('ordered','销量')->totalRow();
        $grid->column('ordered_sales','销售额')->totalRow();
        $grid->disableActions();
        $grid->disableExport();
        $grid->disableCreateButton();
        $grid->disableRowSelector();
        $grid->filter(function($filter){
            $filter->column(1/3, function ($filter) {
                $filter->between('report_date', '日期')->datetime();
            });
            $filter->column(1/3, function ($filter) {
                $filter->equal('country_id','国家')->select(AmazonCountry::options());
            });
            $filter->column(1/3, function ($filter) {
                $filter->equal('classify_id', '品类')->select(ProductClassify::options());
            });
        });
        return $grid;
    }
}
